<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="角色名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入角色名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addRole"
          v-hasPermi="['admin:role:addOrEdit']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          @click="delAllSelection"
          v-hasPermi="['admin:role:addOrEdit']"
        >批量删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="角色编号" prop="id" width="250"/>
      <el-table-column label="角色名称" prop="name" :show-overflow-tooltip="true" width="250"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="250"></el-table-column>
      <el-table-column label="描述" prop="description" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.$index, scope.row)"
            v-hasPermi="['admin:role:addOrEdit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)"
            v-hasPermi="['admin:role:delete']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增或编辑弹出框 -->
    <el-dialog :title="addTitle" :visible.sync="addVisible" width="30%" :close-on-click-modal="false">
      <el-form ref="roleFrom" :model="role" label-width="90px">
        <el-form-item label="角色名">
          <el-input v-model="role.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="role.description" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="权限设置">
          <el-tree
            :data="resource"
            show-checkbox
            node-key="id"
            ref="tree"
            :highlight-current="true"
            :props="defaultProps"
            @check="getChooseData"
          >
              <span class="custom-tree-node" slot-scope="{node,data}">
                  <span>
                      {{ node.label }}
                      <el-tag v-if="data.menuType==='C'" size="mini">菜单</el-tag>
                      <el-tag v-if="data.menuType==='M'" size="mini" type="info">目录</el-tag>
                      <el-tag v-if="data.menuType==='F'" size="mini" type="warning">按钮</el-tag>
                  </span>
              </span>
          </el-tree>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveAdd">确 定</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script src="./role.js"></script>
